package com.lanxiao.cloud.modules.oauth.controller;

import com.lanxiao.cloud.common.core.enums.OperationType;
import com.lanxiao.cloud.common.web.invalid.Log;
import com.lanxiao.cloud.modules.oauth.application.OauthQueryManager;
import com.lanxiao.cloud.modules.oauth.application.dto.LoginCmd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：qiaoliang
 * @date ：2021-09-14
 */
@Api(tags = "登录")
@Validated
@RequestMapping("/oauths")
@RestController
public class LoginController {

  private final OauthQueryManager oauthQueryManager;

  public LoginController(
      OauthQueryManager oauthQueryManager) {
    this.oauthQueryManager = oauthQueryManager;
  }

  @ApiOperation(value = "登录")
  @Log(operationType = OperationType.LOGIN)
  @PostMapping("/login")
  public ResponseEntity<String> login(@Valid @RequestBody LoginCmd login) {
    return ResponseEntity.status(HttpStatus.CREATED).body(oauthQueryManager.login(login));
  }

}
